package com.neoCalf.neoChat.controller;

import com.neoCalf.neoChat.service.ChatMessageService;
import com.neoCalf.neoChat.service.ChatService;
import com.neoCalf.neoCommon.entity.ChatMessage;
import com.neoCalf.neoCommon.entity.ChatSession;
import com.neoCalf.neoCommon.entity.Session;
import com.neoCalf.neoCommon.model.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * @author 小牛
 * @version 1.0
 * @description TODO
 * @date 2025/4/13 2:07
 */
@RestController
@RequestMapping("/chat")
@Validated
public class ChatController {
    @Resource
    private ChatService chatService;
    @Resource
    private ChatMessageService chatMessageService;

    @PostMapping("/addSession")
    public R<String> addSession(@RequestBody @NotNull Session session) {
        chatService.addSession(session);
        return R.ok();
    }

    @PostMapping("/addSessionList")
    public R<String> addSessionList(@RequestBody @NotNull List<Session> sessionList) {
        chatService.addSessionList(sessionList);
        return R.ok();
    }

    @PostMapping("/updateSession")
    void updateSession(@RequestBody Session session) {
        chatService.updateSession(session);
    }

    @PostMapping("/addChatSession")
    public R<String> addChatSession(@RequestBody @NotNull ChatSession chatSession) {
        chatService.addChatSession(chatSession);
        return R.ok();
    }

    @PostMapping("/addChatMessage")
    public R<String> addChatMessage(@RequestBody @NotNull ChatMessage chatMessage) {
        chatService.addChatMessage(chatMessage);
        return R.ok();
    }

    @PostMapping("/addChatMessageList")
    R<String> addChatMessageList(@RequestBody @NotNull List<ChatMessage> chatMessageList) {
        chatMessageService.addChatMessageList(chatMessageList);
        return R.ok();
    }

    @PostMapping("/updateChatSession")
    public R<String> updateChatSession(@RequestBody @NotNull ChatSession chatSession) {
        chatService.updateChatSession(chatSession);
        return R.ok();
    }

    @PostMapping("/findSessionList")
    public R<List<Session>> findSessionList(@RequestParam("userId") String userId) {
        return R.ok(chatService.findSessionList(userId));
    }

    @PostMapping("/findChatMessageList")
    public R<List<ChatMessage>> findChatMessageList(@RequestParam("list") List<String> list) {
        return R.ok(chatService.findChatMessageList(list));
    }

    @PostMapping("/delContactSession")
    R<String> delContactSession(@RequestParam("sessionId") String sessionId) {
        chatService.delContactSession(sessionId);
        return R.ok();
    }

    @PostMapping("/delGroupSessionBatch")
    R<String> delGroupSessionBatch(@RequestParam("list") String[] list, @RequestParam("groupId") String groupId) {
        chatService.delGroupSessionBatch(list, groupId);
        return R.ok();
    }
}
